<?php
 
 
class PhpFox_Mod_Menu_ComponentMenuAdd extends BaseComponent
{
	function process()
	{
		$oSrvMenu = &$this->_oModule->getService('Menu');
	
		$oReq = &App::getRequest();
		
		$aPost = $oReq->getArray('var');
		
		if ( !empty($aPost['title_menu']) && !empty($aPost['url']) && (empty($aPost['edit_id'])) )
		{
			if ( !$oSrvMenu->_checkUrl($aPost['url']) )
			{
				$aError[] = App::format('Mod_Menu.title.in.use');
			}
			
			if ( !isset($aError) )
			{
				$bPageAdded = $oSrvMenu->_add($aPost, false);
			}
		}
		
		if ( (!empty($aPost['edit_id'])) )
		{
			if ( $aPost['old_url'] != $aPost['url'] && !$oSrvMenu->_checkUrl($aPost['url']) )
			{
				$aError[] = App::format('Mod_Menu.title.in.use');
			}
			
			if ( !isset($aError) )
			{
				$bIsPageEdit = $oSrvMenu->_update($aPost, $aPost['edit_id'], false);
			}
		}
		
		if ( $iEditId = $oReq->get('id') )
		{
			$aEditContent = $oSrvMenu->_edit($iEditId);
		}
		
		$this->oTpl->assign(array
		(
			'bPageAdded' => (isset($bPageAdded) ? true : false),
			'aError' => (isset($aError) ? $aError : ''),
			'bIsPageEdit' => (isset($bIsPageEdit) ? $bIsPageEdit : ''),
			'aEdit' => (isset($aEditContent) ? $aEditContent : ''),			
		));
		
		$sHtml = $this->oTpl->fetch("MenuAdd.html");
		
		return $sHtml;
	}
}

?>
